package com.ljw.vendingmachine;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ljw.vendingmachine.bean.MessageEvent;
import com.ljw.vendingmachine.utils.Constant;

import org.greenrobot.eventbus.EventBus;

public class MoreGoodsAnimator implements Animator.AnimatorListener {
    RelativeLayout root;
    TextView text,sumPrice;

    public MoreGoodsAnimator(RelativeLayout root, TextView text,TextView sumPrice) {
        this.root = root;
        this.text = text;
        this.sumPrice=sumPrice;
    }

    @Override
    public void onAnimationStart(Animator animation) {

    }

    @Override
    public void onAnimationEnd(Animator animation) {
        MessageEvent messageEvent=new MessageEvent();
        messageEvent.setCode(Constant.EVENTBUS_CODE_FLUSH_TOTAL_SUMPRICE);
        messageEvent.setMessage("刷新总数和总价");
        EventBus.getDefault().post(messageEvent);
        //动画结束后 父布局移除 img
        Object target = ((ObjectAnimator) animation).getTarget();
        root.removeView((View) target);
        //shopImg 开始一个放大动画
        Animation scaleAnim = AnimationUtils.loadAnimation(root.getContext(), R.anim.shop_scale);
        text.startAnimation(scaleAnim);
    }

    @Override
    public void onAnimationCancel(Animator animation) {

    }

    @Override
    public void onAnimationRepeat(Animator animation) {

    }
}
